package com.elcl.util;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;

import com.elcl.storage.ApplicationCache;

/**
 * 李春霖 2015/09/15 app的类
 * */
public class AppUtils {

	public static PackageInfo getPackageInfo() {
		PackageManager packageManager = ApplicationCache.context
				.getPackageManager();
		try {
			PackageInfo info = packageManager.getPackageInfo(
					ApplicationCache.context.getPackageName(), 0);
			return info;
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * @return 获取app的版本号
	 */
	public static int getAppVersionNumber() {
		PackageInfo info = getPackageInfo();
		int number = 0;
		if (null != info) {
			number = info.versionCode;
		}
		return number;
	}

	/**
	 * @return 获取app的版本名称
	 */
	public static String getAppVersionName() {
		PackageInfo info = getPackageInfo();
		String versionName = "";
		if (null != info) {
			versionName = info.versionName;
		}
		return versionName;
	}

	/**
	 * 获取sdk的版本号
	 */
	public static int getSDKVersionNumber() {
		int sdkVersion;
		try {
			sdkVersion = Integer.valueOf(android.os.Build.VERSION.SDK);
		} catch (NumberFormatException e) {
			sdkVersion = 0;
		}
		return sdkVersion;
	}

}
